package com.power.controller;

import com.power.common.Contants;
import com.power.ov.ResultData;
import com.power.service.UsersService;
import com.power.service.impl.UsersServiceImpl;
import com.power.utils.WriterUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/05 20:37
 * Description:
 * Version: V1.0
 */
@WebServlet("/roleAdd.do")
public class RoleAddController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String roleName=req.getParameter("role_name");
        UsersService usersService=new UsersServiceImpl();
        ResultData resultData=new ResultData();
        try {
            resultData=usersService.addRole(roleName);
        } catch (SQLException e) {
            resultData.setCode(Contants.EXCEPTION);
            resultData.setMsg("系统开小差了....");
            e.printStackTrace();
        }
        WriterUtil.getWriter(resp,resultData);
    }
}
